import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/pages/lf_me/lf_me_logic.dart';
import 'package:largefriends/pages/lf_payment/lf_payment_logic.dart';
import 'package:largefriends/pages/lf_setting/lf_setting_logic.dart';
import 'package:largefriends/pages/lf_verify/lf_verify_logic.dart';
import 'package:largefriends/pages/lf_visibility/lf_visibility_logic.dart';
import 'package:largefriends/res/lf_color.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:largefriends/res/lf_text_style.dart';
import 'package:largefriends/res/lf_widget_ext.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/widgets/custom_cache_image.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';

import '../../res.dart';
import '../lf_edit_profile/lf_edit_profile_logic.dart';
import '../lf_tab_spark/lf_search_filter/lf_search_filter_logic.dart';

class LfMePage extends StatefulWidget {
  const LfMePage({super.key});

  @override
  State<LfMePage> createState() => _LfMePageState();
}

class _LfMePageState extends State<LfMePage> {
  LfMeLogic logic = Get.put(LfMeLogic());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: lfAppBar(actions: [
        InkWell(
          onTap: () {
            toSetting();
          },
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Icon(
              Icons.settings,
              color: colorFF007F,
            ).shadeMask,
          ),
        )
      ]),
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 10.w),
        child: GetBuilder<LfMeLogic>(
          builder: (controller) {
            return Column(
              children: [
                SizedBox(
                  width: 120.r,
                  height: 120.r,
                  child: InkWell(
                    child: Stack(
                      children: [
                        CustomCacheImage(
                          imageUrl:
                              controller.authService.currentAccount!.avatar,
                          isCircle: true,
                          width: 120.r,
                          height: 120.r,
                        ),
                        Align(
                          alignment: Alignment.bottomRight,
                          child: Container(
                            decoration: BoxDecoration(
                                color: colorFF007F,
                                shape: BoxShape.circle,
                                border: Border.all(
                                    color: colorFEFEFE, width: 1.5.r)),
                            margin: EdgeInsets.only(bottom: 3.r, right: 3.r),
                            width: 32.r,
                            height: 32.r,
                            child: Icon(
                              Icons.edit,
                              color: colorFEFEFE,
                              size: 18.r,
                            ),
                          ),
                        )
                      ],
                    ),
                    onTap: () {
                      toEditProfilePage();
                    },
                  ),
                ),
                10.h.sbh,
                Center(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Flexible(
                          child: Text(
                        controller.authService.currentAccount!.username
                            .toUpperCase(),
                        style: lfTextStyle(
                            sp: 18.sp,
                            fontFamily: fontBold,
                            color: colorFEFEFE),
                        overflow: TextOverflow.ellipsis,
                        maxLines: 1,
                      )),
                      controller.authService.currentAccount!.isVerified()? Padding(padding: EdgeInsets.only(left: 5.w),child:  Image.asset(
                        controller.authService.currentAccount!.isVerified()
                            ? Res.ic_verified
                            : Res.ic_verified_no,
                        width: 16.r,)):empty,
                      5.w.sbw,
                      Image.asset(
                        Res.icon_premium,
                        width: 18.r,
                        color: controller.authService.currentAccount!.isGold()
                            ? colorFF007F
                            : Colors.transparent,
                      ),
                    ],
                  ),
                ),
                Center(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        "${controller.authService.currentAccount!.getGenderAbb()}, ${controller.authService.currentAccount!.age}",
                        style: lfTextStyle(
                            sp: 15.sp,
                            fontFamily: fontMedium,
                            color: colorFEFEFE),
                      )
                    ],
                  ),
                ),
                20.h.sbh,
                InkWell(
                  child: Padding(
                    padding:
                        EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
                    child: Row(
                      children: [
                        Expanded(
                          child: Text(
                            strVerification.tr,
                            style: lfTextStyle(
                                sp: 17.sp,
                                fontFamily: fontBold,
                                color: colorFEFEFE),
                          ),
                        ),
                        verificationTip(),
                        Icon(
                          Icons.chevron_right,
                          color: colorFEFEFE,
                        )
                      ],
                    ),
                  ),
                  onTap: () {
                    toVerifyPage();
                    if (logic.authService.currentAccount!.isVerified() ||
                        logic.authService.currentAccount!.verified == 2) {
                      return;
                    }
                    toVerifyPage();
                  },
                ),
                10.h.sbh,
                InkWell(
                  child: Padding(
                    padding:
                        EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
                    child: Row(
                      children: [
                        Expanded(
                          child: Text(
                            strPreferences.tr,
                            style: lfTextStyle(
                                sp: 17.sp,
                                fontFamily: fontBold,
                                color: colorFEFEFE),
                          ),
                        ),
                        Icon(
                          Icons.chevron_right,
                          color: colorFEFEFE,
                        )
                      ],
                    ),
                  ),
                  onTap: () {
                    toLfSearchFilter();
                  },
                ),
                10.h.sbh,
                InkWell(
                  child: Padding(
                    padding:
                        EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
                    child: Row(
                      children: [
                        Expanded(
                          child: Text(
                            strPrivacyAndVisibility.tr,
                            style: lfTextStyle(
                                sp: 17.sp,
                                fontFamily: fontBold,
                                color: colorFEFEFE),
                          ),
                        ),
                        Icon(
                          Icons.chevron_right,
                          color: colorFEFEFE,
                        )
                      ],
                    ),
                  ),
                  onTap: () {
                    toVisibility();
                  },
                ),
                emptyExpand,
                _goldBanner(),
                emptyExpand,
                emptyExpand,
              ],
            );
          },
        ),
      ),
    );
  }

  Widget verificationTip() {
    if (logic.authService.currentAccount!.verified == 1) {
      return Text(
        strVerified.tr,
        style: lfTextStyle(
          sp: 14.sp,
          fontFamily: fontRegular,
          color: colorFEFEFE,
        ),
      );
    }
    if (logic.authService.currentAccount!.verified == 2) {
      return Text(
        strPending.tr,
        style: lfTextStyle(
          sp: 14.sp,
          fontFamily: fontRegular,
          color: colorFEFEFE,
        ),
      );
    }
    if (logic.authService.currentAccount!.verified == 3) {
      return Text(
        strFailed.tr,
        style: lfTextStyle(
          sp: 14.sp,
          fontFamily: fontRegular,
          color: colorFF007F,
        ),
      );
    }
    return const SizedBox.shrink();
  }

  Widget _goldBanner() {
    if (logic.authService.currentAccount!.isGold()) {
      return empty;
    }
    List<String> title = [
      strUnlimitedMessages.tr,
      strSeeWhoLikedYou.tr,
      strStatusSymbol.tr,
      strSeeWhoViewedYou.tr,
      strChooseWhoSeesYou.tr,
      strVoiceMessage.tr,
      strBrowseProfiles.tr
    ];
    List<String> content = [
      strGoldContent1.tr,
      strGoldContent2.tr,
      strGoldContent3.tr,
      strGoldContent4.tr,
      strGoldContent5.tr,
      strGoldContent6.tr,
      strGoldContent7.tr,
    ];

    return Container(
      height: 160.h,
      decoration: BoxDecoration(

          borderRadius: 10.r.radius,
          gradient: LinearGradient(
              begin: const Alignment(-1, -0.9),
              end: const Alignment(0.9, 1),
              colors: [

                colorFF007F.withAlpha(160),
                colorFF007F.withAlpha(150),
                colorFF007F.withAlpha(140),
                colorFF007F.withAlpha(150),
                colorFF007F.withAlpha(160),
                colorFF007F.withAlpha(170),
                colorFF007F.withAlpha(180),

              ])),
      child: InkWell(
        child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 10.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    title[index],
                    style: lfTextStyle(
                        sp: 17.sp, fontFamily: fontBold, color: colorFEFEFE),
                    textAlign: TextAlign.center,
                  ),
                  5.h.sbh,
                  Text(
                    content[index],
                    style: lfTextStyle(
                        sp: 14.sp,
                        fontFamily: fontRegular,
                        color: colorFEFEFE),
                    textAlign: TextAlign.center,
                  ),
                  20.h.sbh,
                  Container(
                      decoration: BoxDecoration(
                          borderRadius: 40.r.radius,
                          border: Border.all(color: colorFEFEFE, width: 2.r)),
                      padding:
                          EdgeInsets.symmetric(horizontal: 20.w, vertical: 2.h),
                      child: Text(
                        strGetVip.tr,
                        style: lfTextStyle(
                            sp: 18.sp,
                            fontFamily: fontBold,
                            color: colorFEFEFE),
                        textAlign: TextAlign.center,
                      ))
                ],
              ),
            );
          },
          pagination: SwiperPagination(
              margin: const EdgeInsets.all(5.0),
              builder: DotSwiperPaginationBuilder(
                  color: Colors.grey,
                  size: 8.r,
                  activeColor: colorFEFEFE,
                  activeSize: 8.r)),
          itemCount: title.length,
          duration: 1000,
          autoplayDelay: 3000,
          autoplay: true,
          control: null,
        ),
        onTap: () {
          toPayment();
        },
      ),
    );
  }
}
